Jenkins - job之间传参

前言:

本文介绍插件: Parameterized Trigger plugin的具体使用方法。


一、插件介绍

Parameterized Trigger plugin插件可以让你在构建完成时触发新的Job构建,并以各种方式为新Job构建指定参数。
当然也可以添加多个配置:每个配置都有一个要触发的Job,触发时间的条件(基于当前构建的结果)和参数部分。


二、使用方法

1、项目Test_A,配置-构建后操作-配置如下信息:

选择【Trigger parameterized build on other projects】

【Projects to build】:项目名称
【Trigger when build is】:项目执行状态
【Add Parameters】:添加需要传的参数

1、【Predefined parameters】:预定义参数,后续的job的入参与当前job的参数名称不一致,或者有新参数的时候,可以使用该传参方式。
局限:后续job的入参的值要么固定,要么由环境变量和入参进行简单的组合获取,无法融入逻辑语句。
2、【Current build parameters】:后续job的入参和用到当前job的入参的时候,可是使用该传参方式。
局限:参数取决于当前的job
3、【Parameters from properties file】:若后续job的入参的值需要一定逻辑处理才能获取,那么,这种传参方式就特别好用了,比较灵活。


image.png

本次传参例子为:JOB_NAME=${JOB_NAME}

2、项目Test_B,配置-参数化构建过程-配置如下信息:

选择【参数化构建过程】

【添加参数-字符参数】:选择字符参数
【名称】:输入参数名称JOB_NAME


image.png

3、项目Test_B,输出传入的参数验证。

选择【构建-Execute shell】

输出传参:echo ${JOB_NAME}


image.png

4、执行项目Test_A后,自动执行项目Test_B,并传入参数${JOB_NAME},查看项目Test_B输出结果。

项目Test_B输出结果如下:


image.png

三、预定义参数

我选择的参数为预定义参数Predefined parameters,那分别有哪些预定义参数可以用呢?

在Build模块下选择Execute shell--the list of available environment variables 选项,可以查看预定义参数信息,如下图:


image.png

如下,列出所有可用的预定义参数:

The following variables are available to shell scripts

BRANCH_NAME((正在构建的分支的名称))
For a multibranch project, this will be set to the name of the branch being built, for example in case you wish to deploy to production from master but not from feature branches; if corresponding to some kind of change request, the name is generally arbitrary (refer to CHANGE_ID and CHANGE_TARGET).


CHANGE_ID
For a multibranch project corresponding to some kind of change request, this will be set to the change ID, such as a pull request number, if supported; else unset.


CHANGE_URL
For a multibranch project corresponding to some kind of change request, this will be set to the change URL, if supported; else unset.


CHANGE_TITLE
For a multibranch project corresponding to some kind of change request, this will be set to the title of the change, if supported; else unset.


CHANGE_AUTHOR
For a multibranch project corresponding to some kind of change request, this will be set to the username of the author of the proposed change, if supported; else unset.


CHANGE_AUTHOR_DISPLAY_NAME
For a multibranch project corresponding to some kind of change request, this will be set to the human name of the author, if supported; else unset.


CHANGE_AUTHOR_EMAIL
For a multibranch project corresponding to some kind of change request, this will be set to the email address of the author, if supported; else unset.


CHANGE_TARGET
For a multibranch project corresponding to some kind of change request, this will be set to the target or base branch to which the change could be merged, if supported; else unset.


BUILD_NUMBER(当前构建的编号)
The current build number, such as "153"


BUILD_ID(当前构建的编号,老的构建会增加时间戳)
The current build ID, identical to BUILD_NUMBER for builds created in 1.597+, but a YYYY-MM-DD_hh-mm-ss timestamp for older builds


BUILD_DISPLAY_NAME(当前构建的显示名)
The display name of the current build, which is something like "#153" by default.


JOB_NAME(当前构建项目的名称)
Name of the project of this build, such as "foo" or "foo/bar".


JOB_BASE_NAME(当前构建项目的短名称)
Short Name of the project of this build stripping off folder paths, such as "foo" for "bar/foo".


BUILD_TAG
String of "jenkins-{JOB_NAME}-{BUILD_NUMBER}". All forward slashes ("/") in the JOB_NAME are replaced with dashes ("-"). Convenient to put into a resource file, a jar file, etc for easier identification.


EXECUTOR_NUMBER
The unique number that identifies the current executor (among executors of the same machine) that’s carrying out this build. This is the number you see in the "build executor status", except that the number starts from 0, not 1.


NODE_NAME
Name of the agent if the build is on an agent, or "master" if run on master


NODE_LABELS
Whitespace-separated list of labels that the node is assigned.


WORKSPACE(构建的目录的绝对路径)
The absolute path of the directory assigned to the build as a workspace.


JENKINS_HOME
The absolute path of the directory assigned on the master node for Jenkins to store data.


JENKINS_URL
Full URL of Jenkins, like http://server:port/jenkins/ (note: only available if Jenkins URL set in system configuration)


BUILD_URL
Full URL of this build, like http://server:port/jenkins/job/foo/15/ (Jenkins URL must be set)


JOB_URL
Full URL of this job, like http://server:port/jenkins/job/foo/ (Jenkins URL must be set)


GIT_COMMIT
The commit hash being checked out.


GIT_PREVIOUS_COMMIT
The hash of the commit last built on this branch, if any.


GIT_PREVIOUS_SUCCESSFUL_COMMIT
The hash of the commit last successfully built on this branch, if any.


GIT_BRANCH
The remote branch name, if any.


GIT_LOCAL_BRANCH
The local branch name being checked out, if applicable.


GIT_URL
The remote URL. If there are multiple, will be GIT_URL_1, GIT_URL_2, etc.


GIT_COMMITTER_NAME
The configured Git committer name, if any.


GIT_AUTHOR_NAME
The configured Git author name, if any.


GIT_COMMITTER_EMAIL
The configured Git committer email, if any.


GIT_AUTHOR_EMAIL
The configured Git author email, if any.


SVN_REVISION
Subversion revision number that's currently checked out to the workspace, such as "12345"


SVN_URL
Subversion URL that's currently checked out to the workspace.


以上~ 如果对你有帮助的话,点赞❤️吧~~

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,290评论 4 363
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,399评论 1 294
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 109,021评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,034评论 0 207
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,412评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,651评论 1 219
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,902评论 2 313
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,605评论 0 199
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,339评论 1 246
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,586评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,076评论 1 261
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,400评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,060评论 3 236
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,083评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,851评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,685评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,595评论 2 270

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,106评论 0 10
  • The Inner Game of Tennis W Timothy Gallwey Jonathan Cape ...
    网事_79a3阅读 11,010评论 2 18
  • 我不是张檬的粉丝,对她的印象也仅仅停留在《古剑奇谭》中温婉大气的方如沁。当时的她,貌不惊艳,却令人难忘。如今看她微...
    林徵阅读 500评论 2 1
  • 是的,我从未如此的慌张。会在某一天听到你的名字后一时想不起你的音容笑貌。 如此这些反复过得悲微、单调的年生很少想起...
    来自明天阅读 267评论 0 0
  • 时间,是爬行在墙上的细纹 是聒噪不停的麻雀,和忙碌的燕子 放学归来的孩子,手里捧着 新采的桑葚,或是抓着蠢笨的知了...
    四夕山人阅读 210评论 0 1